//
//  MainMenuViewController.m
//  muscleLife
//
//  Created by xalo on 16/4/28.
//  Copyright © 2016年 HeavenAndHell. All rights reserved.
//

#import "MainMenuViewController.h"
#import "LoginViewController.h"
#import "UsrDetialViewController.h"
#import "HealthAndDietViewController.h"
#import "PowerRootViewController.h"
#import "RunningViewController.h"


@interface MainMenuViewController ()<UINavigationControllerDelegate>
@property (retain, nonatomic) UIImageView *headImageView;
@property (weak, nonatomic) IBOutlet UIImageView *heathybietImageView;
@property (weak, nonatomic) IBOutlet UIImageView *oxygenSportImageView;
@property (weak, nonatomic) IBOutlet UIImageView *noOxygenSportImageView;
@property (weak, nonatomic) IBOutlet UIImageView *settingView;

@property (assign, nonatomic)BOOL loginState;

@end

@implementation MainMenuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.delegate = self;
//    [self.navigationItem setTitle:@"肌活"];
    /**
     *  测试代码
     */
//    [self updateHealthImage];
    //健康图设置
    [self.heathybietImageView setImage:[UIImage imageNamed:@"rootHealthImg"]];
    //有氧减脂图
    [self.oxygenSportImageView setImage:[UIImage imageNamed:@"rootCharmingImg"]];
    //无氧增肌图
    [self.noOxygenSportImageView setImage:[UIImage imageNamed:@"rootPowerfulImg"]];
    //菜谱查询图
    [self.settingView setImage:[UIImage imageNamed:@"rootUsrImg"]];

    //背景色
    [self.view setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
    [self addTapGesture];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self checkUsr];//检查是否已经登录
}


//给每个图像添加手势按钮
-(void)addTapGesture{

//    UITapGestureRecognizer* tapHeader = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureAction:)];
    UITapGestureRecognizer* tapHeath = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureAction:)];
    UITapGestureRecognizer* tapOxygen = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureAction:)];
    UITapGestureRecognizer* tapNoOxygen = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureAction:)];
    UITapGestureRecognizer* tapSetting = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureAction:)];
    [self.heathybietImageView addGestureRecognizer:tapHeath];
//    [self.headImageView addGestureRecognizer:tapHeader];
    [self.oxygenSportImageView addGestureRecognizer:tapOxygen];
    [self.settingView addGestureRecognizer:tapSetting];
    [self.noOxygenSportImageView addGestureRecognizer:tapNoOxygen];
}

//手势按钮的回调方法 
-(void)tapGestureAction:(UITapGestureRecognizer*)sender{

//    NSLog(@"%ld",sender.view.tag);
    switch (sender.view.tag) {
        case 1004:{
            //判断是否登录
            if (!self.loginState) {
                //没有登录
                LoginViewController* loginVC= [[UIStoryboard storyboardWithName:@"Usr" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
                [self.navigationController pushViewController:loginVC animated:YES];
            }else{
                //已经登录
                UsrDetialViewController* usrDetial = [[UIStoryboard storyboardWithName:@"Usr" bundle:nil] instantiateViewControllerWithIdentifier:@"UsrDetialViewController"];
               [self.navigationController pushViewController:usrDetial animated:YES];
            }
        }break;
        case 1001:{
            HealthAndDietViewController *HealthAndDietVC=[[UIStoryboard storyboardWithName:@"Heath" bundle:nil]instantiateViewControllerWithIdentifier:@"HealthAndDietViewController"];
            [self.navigationController pushViewController:HealthAndDietVC animated:YES];
        }break;
        case 1002:{
           RunningViewController *adjectVC=[[UIStoryboard storyboardWithName:@"Running" bundle:nil]instantiateViewControllerWithIdentifier:@"RunningViewController"];
            [self.navigationController pushViewController:adjectVC animated:YES];
        }
            break;
        case 1003:{

            PowerRootViewController* powerRoot = [[UIStoryboard storyboardWithName:@"Power" bundle:nil] instantiateViewControllerWithIdentifier:@"PowerRootViewController"];
            [self.navigationController pushViewController:powerRoot animated:YES];
        }break;
        default:
            break;
    }
}

#pragma mark - 检测用户是否已经登录
-(void)checkUsr{
    AVUser *currentUser = [AVUser currentUser];
    if (currentUser != nil) {
        // 跳转到首页
        self.loginState = YES;
    } else {
        //缓存用户对象为空时，可打开用户注册界面…
        self.loginState = NO;
    }
}


#pragma mark - tableBar的代理方法
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{

    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
